import React from 'react'
import '../views/Order/Order.less'
import { Modal } from 'antd-mobile';
import { withRouter } from 'react-router-dom'
const alert = Modal.alert;
class OrderBottom extends React.Component {
    order(url) {
        alert('取消', '确定要取消吗???', [
            { text: '取消', onPress: () => console.log('cancel'), style: 'default' },
            {
                text: '确定', onPress: () => {
                    this.$postData(url, { orderId: this.props.data.id }, params => {
                        console.log(params)
                        switch (params.code) {
                            case 100:
                                this.Toast.info(params.msg);
                                window.location.reload()
                                break;
                            default:
                                this.Toast.info(params.msg);
                                break;
                        }
                    })
                }
            },
        ]);
    }
    OkOrder(){
        alert('确认收货', '您要确认收货?', [
            { text: '取消', onPress: () => console.log('cancel'), style: 'default' },
            {
                text: '确定', onPress: () => {
                    this.$postData('/api/order/confirmGood', { orderId: this.props.data.id }, params => {
                        console.log(params)
                        switch (params.code) {
                            case 100:
                                this.Toast.info(params.msg);
                                window.location.reload()
                                break;
                            default:
                                this.Toast.info(params.msg);
                                break;
                        }
                    })
                }
            },
        ]);
    }
    AfterSale(URL) {
        this.props.history.push(`/${URL}/${this.props.data.id}${URL == 'Expressage' ? "" : "/1"}`)
    }
    Pay() {
        this.$getData('/api/otherInfo/isPhone', params => {
            console.log(params)
            switch (params.code) {
                case 100:
                    if (params.statusCode == 1) {
                        this.$postData('/api/payApi/phonePayOrder', { orderNo: this.props.data.id, payType: 2, type: 1, platformType: 3 }, (params) => {
                            console.log('FLSH')
                        })
                    } else {
                        this.props.history.push(`/PayClass/${this.props.data.id}`)
                    }
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
    }
    render() {
        console.log(this.props.data)
        return (
            <div className='OrderTit-d7'>
                <p className='OrderTit-d7-pp'>应付：¥{this.props.data.orderPayPrice}</p>
                {(() => {
                    switch (this.props.data.status) {
                        case 0:
                            return <div className='OrderTit-d8'>
                                <p className={'center OrderTit-d7-p1'} onClick={this.order.bind(this, '/api/order/cancelOrder')}>取消订单</p>
                                <p className={'center OrderTit-d7-p2'} onClick={this.Pay.bind(this)}>付款{parseInt(this.props.data.time / 60)}</p>
                            </div>
                        case 1:
                            return <p className={'center OrderTit-d7-p1'} onClick={this.AfterSale.bind(this, 'AfterSale')}>申请退款</p>
                        case 2:
                            return <div className='OrderTit-d8'>
                                <p className={'center OrderTit-d7-p1'} onClick={this.AfterSale.bind(this, 'Expressage')}>追踪物流</p>
                                <p className={'center OrderTit-d7-p1'} onClick={this.OkOrder.bind(this)}>确认收货</p>
                            </div>
                        case 3:
                            return <p className={'center OrderTit-d7-p1'} onClick={this.AfterSale.bind(this,'Evaluation')}>评价</p>

                    }
                })()}
            </div>
        )
    }
}

export default withRouter(OrderBottom)